package com.g8.pethospitallearnbackend.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.g8.pethospitallearnbackend.entity.Casefields;
import com.g8.pethospitallearnbackend.entity.CasefieldsExample;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

import java.util.List;

@Mapper
public interface CasefieldsMapper extends BaseMapper<Casefields> {
    @SelectProvider(type=CasefieldsSqlProvider.class, method="countByExample")
    long countByExample(CasefieldsExample example);

    @DeleteProvider(type=CasefieldsSqlProvider.class, method="deleteByExample")
    int deleteByExample(CasefieldsExample example);

    @Delete({
        "delete from casefields",
        "where en_attr = #{enAttr,jdbcType=VARCHAR}"
    })
    int deleteByPrimaryKey(String enAttr);

    @Insert({
        "insert into casefields (en_attr, ch_attr)",
        "values (#{enAttr,jdbcType=VARCHAR}, #{chAttr,jdbcType=VARCHAR})"
    })
    int insert(Casefields record);

    @InsertProvider(type=CasefieldsSqlProvider.class, method="insertSelective")
    int insertSelective(Casefields record);

    @SelectProvider(type=CasefieldsSqlProvider.class, method="selectByExample")
    @Results({
        @Result(column="en_attr", property="enAttr", jdbcType=JdbcType.VARCHAR, id=true),
        @Result(column="ch_attr", property="chAttr", jdbcType=JdbcType.VARCHAR)
    })
    List<Casefields> selectByExample(CasefieldsExample example);

    @Select({
        "select",
        "en_attr, ch_attr",
        "from casefields",
        "where en_attr = #{enAttr,jdbcType=VARCHAR}"
    })
    @Results({
        @Result(column="en_attr", property="enAttr", jdbcType=JdbcType.VARCHAR, id=true),
        @Result(column="ch_attr", property="chAttr", jdbcType=JdbcType.VARCHAR)
    })
    Casefields selectByPrimaryKey(String enAttr);

    @UpdateProvider(type=CasefieldsSqlProvider.class, method="updateByExampleSelective")
    int updateByExampleSelective(@Param("record") Casefields record, @Param("example") CasefieldsExample example);

    @UpdateProvider(type=CasefieldsSqlProvider.class, method="updateByExample")
    int updateByExample(@Param("record") Casefields record, @Param("example") CasefieldsExample example);

    @UpdateProvider(type=CasefieldsSqlProvider.class, method="updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(Casefields record);

    @Update({
        "update casefields",
        "set ch_attr = #{chAttr,jdbcType=VARCHAR}",
        "where en_attr = #{enAttr,jdbcType=VARCHAR}"
    })
    int updateByPrimaryKey(Casefields record);

    @Select("select * from casefields")
    List<Casefields> selectAll();

    @Select("select * from casefields order by en_attr <>'default1'")
    List<Casefields> selectAllIdFirst();

    @Select("select en_attr from casefields")
    List<String> selectEnAttr();

    @Select("select en_attr from casefields where ch_attr is null ")
    List<String> selectNULLEnAttr();

    @Select("select ch_attr from casefields")
    List<String> selectChAttr();

    @Select("select en_attr from casefields where ch_attr=#{chAttr}")
    String selectEnAttrByChAttr(@Param("chAttr") String chAttr);

    //#{}会进行一个值的转化，${}直接把列名嵌入进去
    @Update("update `case` set ${enAttr}=NULL")
    void updateTableSetNull(@Param("enAttr") String enAttr);
}